export const getUrlParam = (name) => {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	let url = window.location.href;
	url = url.indexOf('/#/') != -1 ? url : window.location.href.split('#')[0]
	let search = url.split("?")[1];
	if (search) {
		var r = search.substr(0).match(reg);
		if (r !== null) return unescape(r[2]);
		return null;
	} else {
		return null;
	}
}


export const getPageUrl = () => {
	const pages = getCurrentPages();
	const currentPage = pages[pages.length ? pages.length - 1 : 0];
	let pageUrl = `/${currentPage.route}`;
	return pageUrl;
};

export const navigateTo = data => {
	const currentUrl = getPageUrl();
	if (data?.url.includes(currentUrl)) {
		return;
	} else {
		uni.navigateTo({
			url: data?.url
		});
	}
};


export const redirectTo = data => {
	const currentUrl = getPageUrl();
	if (data?.url.includes(currentUrl)) {
		return;
	} else {
		uni.redirectTo({
			url: data?.url
		});
	}
};

export const reLaunch = data => {
	const currentUrl = getPageUrl();
	if (data?.url.includes(currentUrl)) {
		return;
	} else {
		uni.reLaunch({
			url: data?.url
		});
	}
};